package my.mall.admin.api.controller

import jakarta.validation.Valid
import my.mall.admin.api.service.AdminService
import my.mall.admin.api.service.LoginService
import my.mall.admin.api.pojo.admin.AdminDetail
import my.mall.admin.api.pojo.login.LoginInfo
import my.mall.admin.api.pojo.login.LoginParam
import my.mall.common.annotation.Login
import my.mall.common.pojo.CommonResp
import my.mall.common.util.RespUtils
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile

@RestController
@RequestMapping("user")
class AdminController(
    private val adminService: AdminService,
    private val loginService: LoginService
) {

    @PostMapping("login")
    fun login(@RequestBody loginParam: @Valid LoginParam): CommonResp<Map<String, String>> {
        return RespUtils.success(loginService.login(loginParam))
    }

    @GetMapping("info")
    fun getAdminInfo(@Login loginInfo: LoginInfo): CommonResp<AdminDetail> {
        return RespUtils.success(adminService.getAdminInfo(loginInfo.storeId, loginInfo.adminId))
    }

    @PostMapping("upload")
    fun upload(@RequestParam("file") file: MultipartFile?): CommonResp<String> {
        return RespUtils.success("success")
    }
}
